package com.qqt.csr.im.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.qqt.csr.im.enums.ConversationStateEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serial;
import java.io.Serializable;

/**
 * @Author: yang hao
 * @Date: 2024/10/14 9:53
 * @Description: 会话
 **/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Schema(description = "会话")
@Document(collection = "im_conversation")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Conversation implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Id
    @Schema(description = "主键")
    private String id;

    @Indexed(name = "indx_initiatorId")
    @Schema(description = "发起方")
    private String initiatorId;

    @Schema(description = "会话状态，0：结束，1：正常")
    private ConversationStateEnum state;

    @Schema(description = "会话开始时间")
    private String startTime;

    @Schema(description = "会话结束时间")
    private String endTime;

    @Schema(description = "扩展, Json格式")
    private String ext;

    @Indexed(name = "indx_roomId")
    @Schema(description = "房间id")
    private String roomId;

    @Schema(description = "创建时间")
    private String createTime;

    @Schema(description = "更新时间")
    private String updateTime;

    @JsonIgnore
    public boolean isNormal() {
        return ConversationStateEnum.NORMAL.equals(state);
    }

}
